<html xmlns:th="http://www.thymeleaf.org" xmlns:x="http://www.w3.org/1999/html">

<link rel="icon" type="image/x-icon" th:href="@{/static/favicon.ico}">
<link rel="stylesheet" type="text/css" th:href="@{/static/js/jquery-easyui/themes/gray/easyui.css}">
<link rel="stylesheet" type="text/css" th:href="@{/static/js/jquery-easyui/themes/icon.css}">
<link rel="stylesheet" type="text/css" th:href="@{/static/js/jquery-easyui/themes/color.css}">
<link rel="stylesheet" type="text/css" th:href="@{/static/css/common.css}">
<link rel="stylesheet" type="text/css" th:href="@{/static/css/icon.css}">
<script type="text/javascript" th:src="@{/static/js/My97DatePicker/WdatePicker.js}"></script>
<script type="text/javascript">
    var basePath = '[[${#httpServletRequest.getContextPath()}]]';
    window.UEDITOR_HOME_URL = basePath + "/static/js/ueditor/";
    window.UEDITOR_SERVER_URL = basePath + "/ueditor";
</script>
<script type="text/javascript" th:src="@{/static/js/jquery-easyui/jquery.min.js}"></script>
<script type="text/javascript" th:src="@{/static/js/jquery-easyui/jquery.easyui.min.js}"></script>
<script type="text/javascript" th:src="@{/static/js/jquery-easyui/locale/easyui-lang-zh_CN.js}"></script>
<script type="text/javascript" th:src="@{/static/js/arrayToTree.js}"></script>
<script type="text/javascript" th:src="@{/static/js/extJs.js?v=20180425}"></script>
<meta name="_csrf" th:content="${_csrf.token}"/>
<meta name="_csrf_header" th:content="${_csrf.headerName}"/>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',border:false">
        <table id="orderDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="orderToolbar" style="display: none;">
    <!--@sec.hasPermission('item:add'):权限表达式-->
    <div th:if="${@sec.hasPermission('order:add')}">
        <a onclick="orderAddFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'glyphicon-plus icon-green'">添加</a>
    </div>
</div>

<script type="text/javascript">
    var orderDataGrid;
    $(function () {
        orderDataGrid = $('#orderDataGrid').datagrid({
            url: basePath + '/order/dataGrid',
            striped: true,
            pagination: true,
            singleSelect: true,
            idField: 'id',
            pageSize: 20,
            pageList: [10, 20, 30, 40, 50, 100, 200, 300, 400, 500],
            frozenColumns : [ [ {
                width : 60,
                title : '订单ID',
                field : 'orderId',
                sortable : true
            } ] ],
            columns: [ [{
                    width : 200,
                    title : '订单编号',
                    field : 'orderNumber'
                },{
                width : 60,
                title : '客户名称',
                field : 'orderName'
            }, {
                width : 60,
                title : '订单状态',
                field : 'orderStatus'
            }, {
                width : 60,
                title : '付款状态',
                field : 'payStatus'
            },{
                width : 100,
                title : '付款方式',
                field : 'payWay'
            },{
                width : 60,
                title : '物流状态',
                field : 'moveStatus'
            },{
                width : 60,
                title : '订单金额',
                field : 'orderPrice'
            },{
                width : 60,
                title : '实付金额',
                field : 'realityPrice'
            },{
                width : 200,
                title : '下单时间',
                field : 'orderDay'
            },{
                field : 'action',
                title : '操作',
                width : 200,
                formatter : function(value, row, index) {
                    var str = '';
                    /*[# th:if="${@sec.hasPermission('order:edit')}"]*/
                    str += $.formatString('<a href="javascript:void(0)" class="order-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'glyphicon-pencil icon-blue\'" onclick="orderEditFun(\'{0}\');" >编辑</a>', row.orderId);
                    /*[/]*/
                    /*[# th:if="${@sec.hasPermission('order:delete')}"]*/
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="order-easyui-linkbutton-del" data-options="plain:true,iconCls:\'glyphicon-trash icon-red\'" onclick="orderDeleteFun(\'{0}\');" >删除</a>', row.orderId);
                    /*[/]*/
                    return str;
                }
            } ] ],
            onLoadSuccess:function(data){
                $('.order-easyui-linkbutton-edit').linkbutton({text:'编辑'});
                $('.order-easyui-linkbutton-del').linkbutton({text:'删除'});
            },
            toolbar : '#orderToolbar'
        });

    });

    /**
     * 添加框
     * @param url
     */
    function orderAddFun() {
        parent.$.modalDialog({
            title : '添加',
            width : 520,
            height : 300,
            href : basePath + '/order/addPage',
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = orderDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#orderAddForm');
                    f.submit();
                }
            } ]
        });
    }
    /**
     * 编辑
     */
    function orderEditFun(orderId) {
        if (orderId === undefined) {
            var rows = orderDataGrid.datagrid('getSelections');
            orderId = rows[0].orderId;
        } else {
            orderDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.modalDialog({
            title : '编辑',
            width : 520,
            height : 500,
            href : basePath + '/order/editPage?orderId=' + orderId,
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = orderDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#orderEditForm');
                    f.submit();
                }
            } ]
        });
    }

    /**
     * 删除
     */
    function orderDeleteFun(id) {
        if (id === undefined) {//点击右键菜单才会触发这个
            var rows = orderDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {//点击操作里面的删除图标会触发这个
            orderDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.messager.confirm('询问', '您是否要删除当前组织？', function(b) {
            if (b) {
                progressLoad();
                $.post(basePath + '/order/delete', {
                    id : id
                }, function(result) {
                    if (result.code === 1) {
                        parent.$.messager.alert('提示', result.msg, 'info');
                        orderDataGrid.datagrid('reload');
                    }
                    progressClose();
                }, 'JSON');
            }
        });
    }
</script>

